.TH std::filesystem::path::filename 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::filesystem::path::filename \- std::filesystem::path::filename

.SH Synopsis
   path filename() const;  \fI(since C++17)\fP

   Returns the generic-format filename component of the path.

   Equivalent to relative_path().empty() ? path() : *--end().

.SH Parameters

   \fI(none)\fP

.SH Return value

   The filename identified by the path.

.SH Exceptions

   May throw implementation-defined exceptions.

.SH Example


// Run this code

 #include <filesystem>
 #include <iostream>
 namespace fs = std::filesystem;

 int main()
 {
     std::cout << fs::path("/foo/bar.txt").filename() << '\\n'
               << fs::path("/foo/.bar").filename() << '\\n'
               << fs::path("/foo/bar/").filename() << '\\n'
               << fs::path("/foo/.").filename() << '\\n'
               << fs::path("/foo/..").filename() << '\\n'
               << fs::path(".").filename() << '\\n'
               << fs::path("..").filename() << '\\n'
               << fs::path("/").filename() << '\\n'
               << fs::path("//host").filename() << '\\n';
 }

.SH Output:

 "bar.txt"
 ".bar"
 ""
 "."
 ".."
 "."
 ".."
 ""
 "host"

.SH See also

   extension        returns the file extension path component
                    \fI(public member function)\fP
                    returns the stem path component (filename without the final
   stem             extension)
                    \fI(public member function)\fP
   replace_filename replaces the last path component with another path
                    \fI(public member function)\fP
   has_filename     checks if the corresponding path element is not empty
                    \fI(public member function)\fP
